//
//  MCMyBonusContractTableViewCell.m
//  TLYL
//
//  Created by MC on 2017/11/6.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCMyBonusContractTableViewCell.h"
#import "MCDataTool.h"
#import "MCContractMgtTool.h"



@interface MCMyBonusContractTableViewCell()
//用户名：lulu                                           返点：1960
//比   例:  1.2%日结                                状态：已签约
//@property(nonatomic,strong) UIButton * DayWagesProportion;
@property(nonatomic,strong) UIButton * UserName;
//@property(nonatomic,strong) UIButton * Rebate;
@property(nonatomic,strong) UIButton * State;


@property(nonatomic,strong)UIButton * caoZuo;

@end

@implementation MCMyBonusContractTableViewCell
#pragma mark View creation & layout

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //        [self initViews:YES];
        [self createUI];
    }
    return self;
}

-(void)setBtn:(UIButton *)btn WithColor:(UIColor*)color andFont:(UIFont*)font andAlignment:(UIControlContentHorizontalAlignment)alignment andTitle:(NSString *)title{
    [btn setTitleColor:color forState:UIControlStateNormal];
    btn.titleLabel.font=font;
    [btn setTitle:title forState:UIControlStateNormal];
    btn.contentHorizontalAlignment = alignment;
    [self  addSubview:btn];
}
-(void)createUI{
    
    self.backgroundColor=[UIColor whiteColor];
    
    //    用户名：lulu                  返点：1960
    //    比   例:  1.2%日结           状态：已签约
    _UserName =[[UIButton alloc]initWithFrame:CGRectZero];
    [self setBtn:_UserName WithColor:RGB(46, 46, 46) andFont:[UIFont boldSystemFontOfSize:12] andAlignment:UIControlContentHorizontalAlignmentLeft andTitle:@"用户名：加载中..."];
    [_UserName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(15);
        make.left.equalTo(self.mas_left).offset(18);
        make.width.mas_equalTo(250);
        make.height.mas_equalTo(15);
    }];
    

//
//    _Rebate =[[UIButton alloc]initWithFrame:CGRectZero];
//    [self setBtn:_Rebate WithColor:RGB(46, 46, 46) andFont:12 andAlignment:UIControlContentHorizontalAlignmentLeft andTitle:@"返点：加载中..."];
//    [_Rebate mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.mas_top).offset(15);
//        make.left.equalTo(self.mas_left).offset((G_SCREENWIDTH-26)-100);
//        make.width.mas_equalTo(100);
//        make.height.mas_equalTo(15);
//    }];
    
    
    _State =[[UIButton alloc]initWithFrame:CGRectZero];
    [self setBtn:_State WithColor:RGB(46, 46, 46) andFont:[UIFont systemFontOfSize:12] andAlignment:UIControlContentHorizontalAlignmentLeft andTitle:@"状态：加载中..."];
    [_State mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-15);
        make.left.equalTo(self.mas_left).offset(18);
        make.width.mas_equalTo(250);
        make.height.mas_equalTo(15);
    }];
    
    
    
    _caoZuo =[[UIButton alloc]initWithFrame:CGRectZero];
    [self setBtn:_caoZuo WithColor:RGB(46, 46, 46) andFont:[UIFont systemFontOfSize:12] andAlignment:UIControlContentHorizontalAlignmentLeft andTitle:@"【操作】"];
    [_caoZuo setTitleColor:MC_THEME_COLOR forState:UIControlStateNormal];
    [_caoZuo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.right.equalTo(self.mas_right).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
    }];
    
    [_caoZuo addTarget:self action:@selector(action_caoZuo:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
}

-(void)action_caoZuo:(UIButton* )btn{
    
    if (self.bonusBlock) {
        self.bonusBlock();
    }
}



-(void)setDataSource:(MCMyXiaJiBonusContractListDeatailDataModel *)dataSource{
    _dataSource=dataSource;
        //    用户名：lulu                  返点：1960
        //    比   例:  1.2%日结           状态：已签约


    [_UserName setTitle:[NSString stringWithFormat:@"%@",dataSource.UserName] forState:UIControlStateNormal];
    
//    //数组第一个为状态内容，第二个为按钮内容。
//    switch (State){
//        case 0:
//            return ['待确认','修改契约'];
//        case 1:
//            return ['已签约','修改契约'];
//        case 2:
//            return ['未签约','签订契约'];
//    }
//
    NSString * State=@"";
    if([[NSString stringWithFormat:@"%@",dataSource.State]isEqualToString:@"0"]){
        State = @"待确认";
    }else if([[NSString stringWithFormat:@"%@",dataSource.State]isEqualToString:@"1"]){
        State = @"已签约";
    }else if([[NSString stringWithFormat:@"%@",dataSource.State]isEqualToString:@"2"]){
       State = @"未签约";
    }
    [_State setTitle:[NSString stringWithFormat:@"%@，%@",[self GetShowBetRebate:dataSource.Rebate],State] forState:UIControlStateNormal];
    

//    判断自身是否有新的分红契约：
//    get_sub_bonus_new  这个接口中， IsSubContract=1 并且  State =0 ，则提示有新的契约



}


//IsSubContract    Int    是否与下级签约：0=否，隐藏操作按钮；1=是，显示操作按钮
-(void)setIsSubContract:(NSString *)IsSubContract{
    if ([IsSubContract isEqualToString:@"1"]) {
        _caoZuo.hidden=NO;
    }else{
        _caoZuo.hidden=YES;
    }
}

+(CGFloat)computeHeight:(id)info{
    return 70+10;
}

-(NSString * )GetShowBetRebate:(NSString *)Rebate{
    NSString * str = [[NSUserDefaults standardUserDefaults] objectForKey:MerchantMinRebate];
    float fRebate = ([Rebate floatValue] - [str floatValue]) / 20.0;
    return [NSString stringWithFormat:@"%@~%.1f",Rebate,fRebate];
}


@end






































